//
//  WSTransparentViewController.m
//  GroupFourFM
//
//  Created by dllo on 15/12/30.
//  Copyright © 2015年 GroupFour. All rights reserved.
//

#import "WSTransparentViewController.h"
#import "Reachability.h"

@interface WSTransparentViewController ()

@end

@implementation WSTransparentViewController

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.view.backgroundColor = COLOR_BG;
    
    [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor], NSForegroundColorAttributeName, nil]];
    self.navigationController.navigationBar.translucent = YES;
    self.navigationController.navigationBar.barTintColor = [UIColor clearColor];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    //去掉线
    if ([self.navigationController.navigationBar respondsToSelector:@selector( setBackgroundImage:forBarMetrics:)]){
        NSArray *list=self.navigationController.navigationBar.subviews;
        for (id obj in list) {
            if ([obj isKindOfClass:[UIImageView class]]) {
                UIImageView *imageView=(UIImageView *)obj;
                NSArray *list2=imageView.subviews;
                for (id obj2 in list2) {
                    if ([obj2 isKindOfClass:[UIImageView class]]) {
                        UIImageView *imageView2=(UIImageView *)obj2;
                        imageView2.hidden=YES;
                    }
                }
            }
        }
    }
    
    //写所有viewController都做的事
    
    self.messageView = [[UIImageView alloc] initWithFrame:CGRectMake(SCREEN_WIDTH/2, SCREEN_HEIGHT/2, SCREEN_WIDTH*0.6, 30)];
    self.messageView.backgroundColor = CLEAR;
    self.messageView.alpha = 0.8;
    self.messageView.image = [UIImage imageNamed:@"playTimeBg_h@2x.png"];
    self.messageView.center = CGPointMake(SCREEN_WIDTH/2,  SCREEN_HEIGHT *0.75);
    //    [self.messageView sizeToFit];
    
    
    UILabel *messageLabel = [[UILabel alloc] initWithFrame:CGRectMake(5, 0, self.messageView.frame.size.width, self.messageView.frame.size.height)];
    messageLabel.backgroundColor = CLEAR;
    messageLabel.font = [UIFont systemFontOfSize:14];
    messageLabel.textColor = WHITE;
    messageLabel.text = @"没有网络连接,请检查网络后再试!";
    [self.messageView addSubview:messageLabel];
    [UIImageView animateWithDuration:2 delay:2 options:UIViewAnimationOptionLayoutSubviews animations:^{
        
        self.messageView.alpha = 0;
    } completion:^(BOOL finished) {
        
        
    }];
    
    
    Reachability *r = [Reachability reachabilityWithHostName:@"www.apple.com"];
    switch ([r currentReachabilityStatus]) {
        case NotReachable:
            [self.view addSubview:self.messageView];
            [self.view bringSubviewToFront:self.messageView];
            
            NSLog(@"没有网");
            // 没有网络连接
            break;
        case ReachableViaWWAN:
            // 使用3G网络
            NSLog(@"使用3G网络");
            
            break;
        case ReachableViaWiFi:
            // 使用WiFi网络
            NSLog(@"使用WiFi网络");
            
            break;
    }
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
